home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performResample.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.0 KB  |  289 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  February 01, 2001
  22. //
  23. //  Description:
  24. //      This is a script to perfrom the filterCurve command
  25. //        with options for resampling.
  26. //
  27. //  Input Arguments:
  28. //        int action        0 - just execute the command
  29. //                        1 - show the option box dialog
  30. //                        2 - return the drag command
  31. //
  32. //  Return Value:
  33. //      None.
  34. //
  35.  
  36. proc setOptionVars (int $forceFactorySettings)
  37. {
  38.     keySetOptionBoxCommon( { "resample", 
  39.                              "unknown",
  40.                              "setOptionVars", 
  41.                              $forceFactorySettings } );
  42.  
  43.     // Resample kernel types
  44.     //
  45.     //    1: Closest Sample
  46.     //    2: Linear Interpolation
  47.     //    3: Box Filter
  48.     //    4: Triangle Filter
  49.     //    5: Gaussian 2
  50.     //    6: Gaussian 4
  51.     //
  52.     if ($forceFactorySettings || 
  53.         !`optionVar -exists resampleKernel`) {
  54.         optionVar -intValue resampleKernel 5;
  55.     }
  56.  
  57.     // timeStep
  58.     //
  59.     if ($forceFactorySettings || !`optionVar -exists resampleTimeStep`) {
  60.         optionVar -floatValue resampleTimeStep 1.0;
  61.     }
  62. }
  63.  
  64. global proc resampleSetup (string $parent, string $selectionConnection, int $forceFactorySettings)
  65. {
  66.     // Retrieve the option settings
  67.     //
  68.     setOptionVars ($forceFactorySettings);
  69.  
  70.     setParent $parent;
  71.  
  72.     keySetOptionBoxCommon( { "resample", $selectionConnection, "setup", 0 } );
  73.  
  74.     // Set the correct menu for the resample kernel
  75.     //
  76.     int $kernel = `optionVar -query resampleKernel`;
  77.     if ($kernel < 1 || $kernel > 6) {
  78.         $kernel = 5;
  79.     }
  80.     optionMenuGrp -e -sl $kernel resampleKernelMenuGrp;
  81.  
  82.     // -timeStep
  83.     //
  84.     float $timeStep = `optionVar -query resampleTimeStep`;
  85.     floatFieldGrp -edit -value1 $timeStep resampleTimeStep;
  86.  
  87.     resampleWidgetsEnable ($selectionConnection);
  88. }
  89.  
  90.  
  91. global proc resampleCallback( string $parent, int $doIt,
  92.                               string $selectionConnection, int $performAction )
  93. {
  94.     setParent $parent;
  95.  
  96.     keySetOptionBoxCommon( { "resample", $selectionConnection, "callback" } );
  97.  
  98.     //    Resample kernel
  99.     //
  100.     int $kernel = `optionMenuGrp -q -sl resampleKernelMenuGrp`;
  101.     optionVar -intValue resampleKernel $kernel;
  102.  
  103.     // -timeStep
  104.     //
  105.     optionVar
  106.         -floatValue
  107.         resampleTimeStep
  108.         `floatFieldGrp -query -value1 resampleTimeStep`;
  109.  
  110.     if( $doIt ) {
  111.         performResample( $performAction, $selectionConnection);
  112.         string $tmpCmd = "performResample ";
  113.         $tmpCmd += "\"" + $performAction + "\", ";
  114.         $tmpCmd += "\"" + $selectionConnection + "\"";
  115.         addToRecentCommandQueue $tmpCmd "Resample";
  116.     }
  117. }
  118.  
  119. global proc resampleWidgetsEnable(string $selectionConnection)
  120. {
  121.     keySetOptionBoxCommon( { "resample", $selectionConnection, "enable" } );    
  122. }
  123.  
  124. proc string resampleWidgets( string $tabLayout, string $selectionConnection )
  125. {
  126.     setParent $tabLayout;
  127.  
  128.     string $tabForm = `columnLayout -adjustableColumn true`;
  129.  
  130.     keySetOptionBoxCommon( { "resample", $selectionConnection, "widgets", 1, 0, 1 } );
  131.  
  132.     optionMenuGrp -l "Resample Type" resampleKernelMenuGrp;
  133.         menuItem "Closest Sample";
  134.         menuItem "Linear Interpolation";
  135.         menuItem "Box Filter";
  136.         menuItem "Triangle Filter";
  137.         menuItem "Gaussian 2";
  138.         menuItem "Gaussian 4";
  139.  
  140.     floatFieldGrp -label "Time Step" -precision 2 -value1 1.0 resampleTimeStep;
  141.  
  142.     return $tabForm;
  143. }
  144.  
  145. global proc resampleDoSelectionChanged(string $selectionConnection)
  146. //
  147. // Description:
  148. //    Since timeRange is irrelevant when there are 
  149. //    picked keyframes, collapse the timeRange
  150. //    when there are.  (This is hooked in to a SelectionChanged
  151. //    trigger.)
  152. //
  153. {
  154.     keySetOptionBoxCommon( { "resample", $selectionConnection, "selectionChanged" } );
  155.     resampleWidgetsEnable ($selectionConnection);
  156. }
  157.  
  158.  
  159. proc resampleOptions( string $selectionConnection, int $performAction )
  160. {
  161.     // Customisation options
  162.     //
  163.     // Name of the command for this option box (think of it as the base class)
  164.     string $commandName = "resample";
  165.     // Title for the option box window
  166.     string $optionBoxTitle = "Resample Curve Options";
  167.     // Title for the apply button
  168.     string $applyTitle = "Resample";
  169.  
  170.     // Build the option box "methods"
  171.     //
  172.     string $callback = ($commandName + "Callback");
  173.     string $setup = ($commandName + "Setup");
  174.  
  175.     // Build the window, with a tab layout
  176.     //
  177.     string $widgetList[] = `getStandardWindow $optionBoxTitle 0 "noOptions"`;
  178.     setUITemplate -pushTemplate DefaultTemplate;
  179.  
  180.     // Make the form invisible while we create the widgets in the window
  181.     //
  182.     formLayout -e -vis false $widgetList[1];
  183.  
  184.     // Attach each tab
  185.     //
  186.     resampleWidgets $widgetList[2] $selectionConnection;
  187.  
  188.     // Attach the standard buttons
  189.     //
  190.     string $buttonList[] = `addStandardButtons $commandName $applyTitle 
  191.         $widgetList[1] $widgetList[2] "noOptions"`;
  192.  
  193.     // attach commands to the standard buttons
  194.     //
  195.     // Save
  196.     //
  197.     button -e -c ($callback + " " + $widgetList[0] + " false \"\" " + $performAction +
  198.                   "; hideOptionBox()") $buttonList[3];
  199.  
  200.     // Close
  201.     //
  202.     button -edit -command hideOptionBox $buttonList[2];
  203.  
  204.     // Reset
  205.     //
  206.     button -edit -command ($setup + " " + $widgetList[0] + " " + $selectionConnection + " true") $buttonList[1];
  207.  
  208.     // Do It
  209.     //
  210.     button -edit -command ($callback + " " + $widgetList[0] + " true \"" +
  211.                            $selectionConnection + "\"" + $performAction) $buttonList[0];
  212.  
  213.     // Make the form layout visible so we can see what we built, and
  214.     // reset the template
  215.     //
  216.     formLayout -e -vis true $widgetList[1];
  217.     setUITemplate -popTemplate;
  218.  
  219.     //    Customize the 'Help' menu item text.
  220.     //
  221.     setOptionBoxHelpTag( "ResampleCurves" );
  222.  
  223.     // Call the setup "method" to fill in the current settings
  224.     //
  225.     eval (($setup + " " + $widgetList[0] + " " + $selectionConnection + " false"));    
  226.     showOptionBox();
  227.     showWindow $widgetList[0];
  228.  
  229.     resampleDoSelectionChanged($selectionConnection);    
  230.     scriptJob -protected
  231.         -event "SelectionChanged" ("resampleDoSelectionChanged " + $selectionConnection) 
  232.         -parent $widgetList[2];
  233. }
  234.  
  235. proc string assembleCmd( string $selectionConnection, string $options ) 
  236. {
  237.     string $cmd = "doResampleArgList 1 { " + 
  238.                 "\"" + `optionVar -q resampleWhichRange` + "\"" +
  239.                 ",\"" + `optionVar -q resampleRange` + "\"" +
  240.                 ",\"" + `optionVar -q resampleKernel` + "\"" +
  241.                 ",\"" + `optionVar -q resampleTimeStep` + "\"" +
  242.                 ",\"" + $selectionConnection + "\"" +
  243.                 ",\"" + $options + "\"" +
  244.             " };";        
  245.  
  246.     return $cmd;
  247. }
  248.  
  249. // The action variable means
  250. //        0 - do the command
  251. //        1 - show the option box
  252. //        2 - return the drag command
  253. //        3 - do the command (bufferCurve version)
  254. //        4 - show the option box (bufferCurve version)
  255. //        5 - return the drag command (bufferCurve version)
  256. //
  257. global proc string performResample( int $action, string $selectionConnection )
  258. {
  259.     string $cmd = "";
  260.  
  261.     switch( $action ) {
  262.     case 0:
  263.         setOptionVars( false );
  264.         $cmd = assembleCmd( $selectionConnection, "noOptions" );
  265.         eval( $cmd );
  266.         break;
  267.     case 1:
  268.         resampleOptions( $selectionConnection, 0 );
  269.         break;
  270.     case 2:
  271.         setOptionVars( false );
  272.         $cmd = assembleCmd( $selectionConnection, "noOptions" );
  273.         break;
  274.     case 3:
  275.         setOptionVars( false );
  276.         $cmd = assembleCmd( $selectionConnection, "bufferCurve" );
  277.         eval( $cmd );
  278.         break;
  279.     case 4:
  280.         resampleOptions( $selectionConnection, 3 );
  281.         break;
  282.     case 5:
  283.         setOptionVars( false );
  284.         $cmd = assembleCmd( $selectionConnection, "bufferCurve" );
  285.         break;
  286.     }
  287.     return ($cmd);
  288. }
  289.